<template>
	<div class="repair">
		<van-nav-bar title="设备异常列表" left-arrow="" @click-left='goBack()'>
			<van-button @click='goRepairList' type="primary" slot='right' color="#62cff9">维修列表</van-button>
		</van-nav-bar>
		<div class="area">
			<van-search placeholder="搜索设备编号" @input='getObscureDevice' v-model="searchData" :clearable="true" show-action="">
				<div slot="action" @click="onSearch">搜索</div>
			</van-search>
      <van-overlay :show="show" @click="show = false">
        <van-cell @click='getDeviceName(item.facilityname,item.id)' v-for="(item,i) in deviceList" :key='i' :title="item.facilityname"></van-cell>
      </van-overlay>
			<repair :status='false' :allInfo='allInfo'></repair>
		</div>
	</div>
</template>

<script>
	import repair from '../subcom/repair.vue'
	import {Toast} from 'vant'
	export default {
		data() {
			return {
        show:false,
				//showkeywords: false,
				allInfo:[],
				searchData:'',
        deviceList:[]
			}
		},
    watch:{
      searchData(newVal){
        this.show = true
        this.onSearch()
      }
    },
		created(){
		},
		methods:{
      //根据输入的设备名字获得具体的设备名称
      getDeviceName(name,id){
        this.searchData = name
        this.num = id
      },
      //模糊查询获得设备列表
      getObscureDevice(){
        this.$axios.post('/Maintenance/obscureFacility.do',{facilityName:this.searchData}).then(res=>{
          if(res.data.status === 200){
            this.deviceList = res.data.msg
          }
        })
      },
			onSearch(){
				 this.$axios.post('/Maintenance/selectMaintenance.do',{facilityid:this.searchData,id:'',starttime:'',endtime:''}).then(res=>{
				    if(res.data.status === 200){
				        let newData = res.data.msg

				        newData.map((value,index)=>{
				        	if(value.state === 1){

				        		this.allInfo.push(value)
				        	}
				        })
				        if(this.allInfo.length === 0){
				            Toast.fail({message:'暂无数据',duration:900})
				        }
				    }

				})
			},
			getAllInfo(){
				this.$axios.post('/Maintenance/selectAllMaintenance.do').then(res=>{
					if(res.data.status===200){
						let newData = res.data.msg

						newData.map((value,index)=>{
							if(!value.maintanceusername){

								this.allInfo.push(value)
							}
						})
						if(this.allInfo.length === 0){
							Toast.fail({message:'暂无异常设备'})
						}

					}
				console.log(this.allInfo);

				})
			},

			goRepairList(){
				this.$router.push({name:'repairdeviceList',params:{isMe:false}})
			}
		},
		components:{repair}
	}
</script>

<style scoped="scoped">
  .van-overlay{
    top: 7rem;
  }
	img{
		vertical-align: middle;
		height: 1.2rem;
		width: 1.2rem;
	}

	van-button {
		color: #999;
	}

	.van-button--default {
		border: none;
		color: #999999;
	}

	.keywords {
		font-size: .8rem;
		margin-bottom: .8rem;
	}
	.van-button {
		border-radius: 7px;
		height: 1.8rem;
		line-height: 1.8rem;
		font-size: .8rem;
		padding-left: .4rem;
		padding-right: .4rem;
	}
</style>
